package org.jxy.study.rpc.netty.hander;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.jxy.study.rpc.message.DataMsg;

/**
 * @author jxy
 * @className DataMsgToByteMsgEncoder
 * @description 将DataMsg数据转换为byte写出
 * @date 2021/3/10 22:02
 */
public class DataMsgToByteMsgEncoder extends MessageToByteEncoder<DataMsg> {
    protected void encode(ChannelHandlerContext ctx, DataMsg msg, ByteBuf out) throws Exception {
        out.writeInt(msg.getLength());
        out.writeBytes(msg.getData());
    }
}
